package com.laomou.poker.rule.bull;

import java.util.Random;

import com.java.rapid.Condition;
import com.java.rapid.list.raList;
import com.laomou.poker.Poker;
import com.laomou.poker.PokerGroup;
import com.laomou.poker.PokerNum;
import com.laomou.poker.main.Log;
import com.laomou.poker.player.AbsPlayer;
import com.laomou.poker.rule.PokerRuleType;
import com.laomou.poker.table.Table;

public class BullTable extends Table {

    public BullTable() {
        super(PokerRuleType.斗牛);
    }

    @Override
    public void onPreDealPoker() {
        raList.from(getPushPoker()).remove(new Condition<Poker>() {

            @Override
            public boolean apply(Poker input) {
                if (input.getPokerNum() == PokerNum.大王
                        || input.getPokerNum() == PokerNum.小王) {
                    return true;
                }
                return false;
            }
        });
    }

    @Override
    public void onPrePoker() {
        Random r = new java.util.Random();
        int size = getPlayer().size();
        int n = r.nextInt(size);
        for (int i = 0; i < size; i++) {
            if (i == n) {
                setStart(i);
                getPlayer(i).setPlayerType(BullType.头家);
            } else {
                getPlayer(i).setPlayerType(BullType.平民);
            }
        }
    }

    @Override
    public void onStart() {
        int j = getStart();
        AbsPlayer led = getPlayer(j);
        PokerGroup ledPoker = led.getFirstDiscardPoker();
        mRule.isRule(ledPoker);
        Log.print(led.getPlayerName() + " 的牌 " + ledPoker);
        for (int i = 0; i < getPlayer().size(); i++) {
            if (j == i) {
                continue;
            }
            AbsPlayer p = getPlayer(i);
            PokerGroup myPoker = p.getFirstDiscardPoker();
            mRule.isRule(myPoker);
            if (mRule.isGreater(myPoker, ledPoker)) {
                Log.print(p.getPlayerName() + " 大于庄家的牌 " + myPoker);
            } else {
                mTableNewPoker = p.getFirstDiscardPoker();
                Log.print(p.getPlayerName() + " 小于庄家的牌  " + myPoker);
            }
        }
    }
}
